package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	_ "net/http/pprof"
)

// net/http server

func f1(w http.ResponseWriter, r *http.Request){
	//str := `<h1>hello golang</h1>`
	b, err := ioutil.ReadFile("./xx.txt")
	if err != nil{
		w.Write([]byte(fmt.Sprintf("%v", err)))
	}
	w.Write(b)
}


func f2(w http.ResponseWriter, r *http.Request){
	// 对于GEt请求，参数都放在URL上（query param）,请求体中是没有数据的
	fmt.Println(r.URL)
	queryParam := r.URL.Query()	// 自动帮我们识别URL中的参数
	queryParam.Get("name")
	fmt.Println(queryParam)
	fmt.Println(r.Method)
	fmt.Println(ioutil.ReadAll(r.Body))	// 我在服务端打印客户端发来的请求的body
	w.Write([]byte("ok"))
}



func main(){
	http.HandleFunc("/posts/Go/1/", f1)
	http.HandleFunc("/xxx/", f2)
	http.ListenAndServe("127.0.0.1:9090", nil)
}